package com.tc.modules.sys.service.impl;

import com.tc.modules.sys.mapper.SysRoleResourceMapper;
import com.tc.modules.sys.model.entity.SysButton;
import com.tc.modules.sys.model.entity.SysRole;
import com.tc.modules.sys.service.ISysRoleResourceService;
import com.xiaoleilu.hutool.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Auther: tianchao
 * @Date: 2020/4/25 13:30
 * @Description:
 */
@Service
public class SysRoleResourceServiceImpl implements ISysRoleResourceService {

    @Autowired
    private SysRoleResourceMapper sysRoleResourceMapper;
    /**
     * 获取角色的权限标识
     *
     * @param roleList 角色list
     * @return 权限标识
     */
    @Override
    public List<String> selectPermissionByRoles(List<SysRole> roleList) {
        return CollectionUtil.isEmpty(roleList) ? null : sysRoleResourceMapper.selectPermissionByRoles(roleList);
    }

    /**
     * 获取角色授权的访问路径信息
     *
     * @param roleCode 角色编码
     * @return 访问路径信息list
     */
    @Cacheable(value = "auth_permission", key = "#roleCode  + '_permission'")
    @Override
    public Set<SysButton> selectButtonByRole(String roleCode) {
        return sysRoleResourceMapper.selectButtonByRole(roleCode);
    }
}
